package com.ktg.mes.wm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ktg.common.annotation.Log;
import com.ktg.common.core.controller.BaseController;
import com.ktg.common.core.domain.AjaxResult;
import com.ktg.common.enums.BusinessType;
import com.ktg.mes.wm.domain.WmItemConsumeDetail;
import com.ktg.mes.wm.service.IWmItemConsumeDetailService;
import com.ktg.common.utils.poi.ExcelUtil;
import com.ktg.common.core.page.TableDataInfo;

/**
 * 物料消耗记录明细Controller
 * 
 * @author yinjinlu
 * @date 2025-03-07
 */
@RestController
@RequestMapping("/mes/wm/itemconsumedetail")
public class WmItemConsumeDetailController extends BaseController
{
    @Autowired
    private IWmItemConsumeDetailService wmItemConsumeDetailService;

    /**
     * 查询物料消耗记录明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(WmItemConsumeDetail wmItemConsumeDetail)
    {
        startPage();
        List<WmItemConsumeDetail> list = wmItemConsumeDetailService.selectWmItemConsumeDetailList(wmItemConsumeDetail);
        return getDataTable(list);
    }

    /**
     * 导出物料消耗记录明细列表
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:export')")
    @Log(title = "物料消耗记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmItemConsumeDetail wmItemConsumeDetail)
    {
        List<WmItemConsumeDetail> list = wmItemConsumeDetailService.selectWmItemConsumeDetailList(wmItemConsumeDetail);
        ExcelUtil<WmItemConsumeDetail> util = new ExcelUtil<WmItemConsumeDetail>(WmItemConsumeDetail.class);
        util.exportExcel(response, list, "物料消耗记录明细数据");
    }

    /**
     * 获取物料消耗记录明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:query')")
    @GetMapping(value = "/{detailId}")
    public AjaxResult getInfo(@PathVariable("detailId") Long detailId)
    {
        return AjaxResult.success(wmItemConsumeDetailService.selectWmItemConsumeDetailByDetailId(detailId));
    }

    /**
     * 新增物料消耗记录明细
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:add')")
    @Log(title = "物料消耗记录明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WmItemConsumeDetail wmItemConsumeDetail)
    {
        return toAjax(wmItemConsumeDetailService.insertWmItemConsumeDetail(wmItemConsumeDetail));
    }

    /**
     * 修改物料消耗记录明细
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:edit')")
    @Log(title = "物料消耗记录明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WmItemConsumeDetail wmItemConsumeDetail)
    {
        return toAjax(wmItemConsumeDetailService.updateWmItemConsumeDetail(wmItemConsumeDetail));
    }

    /**
     * 删除物料消耗记录明细
     */
    @PreAuthorize("@ss.hasPermi('mes:wm:itemconsumedetail:remove')")
    @Log(title = "物料消耗记录明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{detailIds}")
    public AjaxResult remove(@PathVariable Long[] detailIds)
    {
        return toAjax(wmItemConsumeDetailService.deleteWmItemConsumeDetailByDetailIds(detailIds));
    }
}
